package com.qidian.buy.controller;

import com.qidian.buy.pojo.Content;
import com.qidian.buy.service.ContentService;
import com.qidian.buy.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/6 10:58
 */
@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @GetMapping("/indexData")
    public QdResult indexData(){
        return contentService.queryIndexData();
    }
    @GetMapping("/queryByCatId")
    public QdResult queryByCatId(Long catId,@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return contentService.queryByCatId(catId,page,limit);
    }
    @GetMapping("/queryByCatMark")
    public QdResult queryByCatMark(String catMark,@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return contentService.queryByCatMark(catMark,page,limit);
    }

    @GetMapping("/get")
    public QdResult get(Long contentId){
        return contentService.queryById(contentId);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody Content content){
        return contentService.save(content);
    }

    @PostMapping("/edit")
    public QdResult edit(@RequestBody Content content){
        return contentService.update(content);
    }

    @GetMapping("/list")
    public QdResult list(Content content,@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return contentService.list(content,page,limit);
    };
}
